package com.smarthome.core.dictionary.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.smarthome.base.service.ShEquipmentTypeService;
import com.smarthome.core.dictionary.DeviceTypeService;
import com.smarthome.domain.bean.ShEquipmentType;
import com.smarthome.domain.vo.boss.Combobox;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

@Service("deviceTypeService")
public class DeviceTypeServiceImpl implements DeviceTypeService {
	@Resource
	private ShEquipmentTypeService equipService;
	@Override
	public DataGrid queryDatagrid(ShEquipmentType deviceType, PageHelper helper) {
		return equipService.queryDatagrid(deviceType, helper);
	}

	@Override
	public List<ShEquipmentType> queryDeviceTypeByCondition(
			ShEquipmentType deviceType) {
		return equipService.selectEntryList(deviceType);
	}

	@Override
	public ShEquipmentType queryDeviceTypeById(Long id) {
		return equipService.selectEntryById(id);
	}

	@Override
	public void add(ShEquipmentType deviceType) {
		equipService.saveOrUpdate(deviceType);
	}

	@Override
	public void edit(ShEquipmentType deviceType) {
		equipService.saveOrUpdate(deviceType);
	}

	@Override
	public void delete(Long id) {
		ShEquipmentType deviceType=queryDeviceTypeById(id);
		deviceType.setIsDel(1L);
		equipService.saveOrUpdate(deviceType);
	}

	/**
	 * 得到设备类型下拉选项
	 * @author szc
	 */
	@Override
	public List<Combobox> getDeviceTypeCombobox(boolean flag) {
		List<Combobox> result = new ArrayList<>();
		if(flag) {
			Combobox combobox = new Combobox();
			combobox.setValue("");
			combobox.setText("--请选择--");
			combobox.setSelected(true);
			result.add(combobox);
		}
		ShEquipmentType equipmentType = new ShEquipmentType();
		equipmentType.setOrderField("id");
		equipmentType.setOrderFieldType("ASC");
		equipmentType.setIsDel(0L);
		List<ShEquipmentType> equipmentTypes = this.queryDeviceTypeByCondition(equipmentType);
		//转combobox
		for(ShEquipmentType type:equipmentTypes) {
			Combobox combobox = new Combobox();
			combobox.setValue(type.getId().toString());
			combobox.setText(type.getName());
			result.add(combobox);
		}
		return result;
	}
	
}
